﻿Imports UCBase
Imports System.Text
Imports System.IO

Public Class UCNet
    Implements UCBase.I_UCNet
    Implements UCBase.I_LoadSave

    Private WithEvents DataIO As UCBase.I_BinaryDataExchange
    Private DataEncoder As New UCS_HardwareIO.Encoder(10, 1)
    Private DataBuilder As New UCS_HardwareIO.DataBuilder


    Private Sub DataOut_Connect() Handles DataOut.Connect
        Dim S As Socket = DataOut.Remote
        DataIO = S.Parent
    End Sub
    Public Sub Write(ByVal AddrA As Integer, ByVal AddrB As Integer, ByVal Command As Integer, ByVal Value As Integer) Implements UCBase.I_UCNet.Write
        'Dim B(4) As Byte
        'Dim S As String = Convert.ToString(Value, 2).PadLeft(16, "0")
        'Dim B1 As Byte = Convert.ToByte(S.Substring(0, 8), 2)
        'Dim B2 As Byte = Convert.ToByte(S.Substring(8, 8), 2)
        'B(0) = CByte(AddrA)
        'B(1) = CByte(AddrB)
        'B(2) = CByte(Command)
        'B(3) = CByte(B1)
        'B(4) = CByte(B2)
        DataIO.ClearBuffers()
        DataIO.Write(DataEncoder.Encode(1, 1))
    End Sub
    Public Function Read(ByVal AddrA As Integer, ByVal AddrB As Integer, ByVal Command As Integer, ByVal Value As Integer, Optional ByVal ByteCountToRead As Integer = 2) As Byte() Implements UCBase.I_UCNet.Read
        DataIO.ClearBuffers()
        DataIO.Write(DataEncoder.Encode(DataBuilder.CreateThreeByte(1, 1)))


        Dim Bc As Integer = 0
        Do
            Bc = DataIO.BytesToRead
        Loop Until Bc = ByteCountToRead

        'Dim OutBytes(ByteCountToRead - 1) As Byte
        'OutBytes = DataIO.Read
        Return DataEncoder.Encode(DataBuilder.CreateThreeByte(1, 1))

    End Function

    Public Function GetSettings() As String Implements UCBase.I_LoadSave.GetSettings
        Return ""
    End Function

    Public Sub SetSettings(ByVal Settings As String) Implements UCBase.I_LoadSave.SetSettings

    End Sub
End Class
